package com.lance.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * @author lancecong
 * @version 1.0
 * @ClassName WebFluxDemo
 * @DESCRIPTION TODO
 * @create 2019-06-15 22:12
 **/
@RestController
@Slf4j
public class WebFluxDemo {
    @Resource
    private WebClient.Builder webclientBuilder;

    @GetMapping("/webflux")
    public Mono<String> webFlux(){
        Mono<String> result = webclientBuilder.build().get()
                .uri("http://micro-nacos/conf/get").retrieve().bodyToMono(String.class);
        return result;
    }

    @Bean
    @LoadBalanced
    public WebClient.Builder loadBalancedWebClientBuilder() {
        return WebClient.builder();
    }

}
